package com.mall.dao;

import com.mall.domain.ItemCat;
import com.mall.domain.MsAnnouncement;
import com.mall.domain.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 商品类别的持久层接口
 * @author : liangY
 * @date : 2021-01-04 16:48
 */
@Repository
public interface AnnouncementDao {

    /**
     * 查询所有公告
     * @param page 分页实体类
     * @return
     */
    @Select("select * from tb_announcement where title like #{page.query} limit #{page.num},#{page.size}")
    List<MsAnnouncement> findAll(@Param("page") Page page);

    /**
     * 查询公共根据ID
     * @param id 分页实体类
     * @return
     */
    @Select("select * from tb_announcement where id = #{id}")
    MsAnnouncement findById(@Param("id") Integer id);
    /**
     * 统计公告信息
     *
     * @return
     */
    @Select("select count(*) from tb_announcement where title like #{title}")
    Integer findTotal(String title);

    /**
     * 更新公告
     * @param itemCat 商品分类实体类
     * @return
     */
    @Update("update tb_announcement set title=#{title},content_text=#{content_text}," +
            "date=#{date},ment_typ=#{ment_typ}  where id=#{id}")
    Integer update(MsAnnouncement itemCat);

    /**
     * 添加公告
     * @param itemCat 添加公告
     * @return
     */
    @Insert("insert into tb_announcement (id,title,content_text,date,ment_typ)" +
            "values(#{id},#{title},#{content_text},#{date},#{ment_typ})")
    @SelectKey(keyColumn = "id", keyProperty = "id", resultType = Integer.class,
            before = false, statement = {"select last_insert_id()"})
    Integer addMsAnnouncement(MsAnnouncement itemCat);

    /**
     * 删除公告
     * @param id id
     * @return
     */
    @Delete("delete from tb_announcement where id = #{id}")
    Integer del(Integer id);
}
